package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@Slf4j
@RequestMapping("/checkitem")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;

    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.debug("CheckItemController__findByPage:{" + queryPageBean + "}");
        PageResult pageResult = checkItemService.findByPage(queryPageBean);
        log.debug(MessageConst.QUERY_CHECKITEM_SUCCESS);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, pageResult);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        log.debug("CheckItemController__add:{" + checkItem + "}");
        checkItemService.add(checkItem);
        log.debug(MessageConst.ADD_CHECKITEM_SUCCESS);
        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }

    @RequestMapping("/findById")
    public Result findById(Integer id) {
        log.debug("CheckItemController__findById:{" + id + "}");
        CheckItem checkItem = checkItemService.findById(id);
        log.debug(MessageConst.QUERY_CHECKITEM_SUCCESS);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, checkItem);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody CheckItem checkItem) {
        log.debug("CheckItemController__update:{" + checkItem + "}");
        checkItemService.update(checkItem);
        log.debug(MessageConst.EDIT_CHECKITEM_SUCCESS);
        return new Result(true, MessageConst.EDIT_CHECKITEM_SUCCESS);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        log.debug("CheckItemController__deleteById:{" + id + "}");
        checkItemService.deleteById(id);
        log.debug(MessageConst.DELETE_CHECKITEM_SUCCESS);
        return new Result(true, MessageConst.DELETE_CHECKITEM_SUCCESS);
    }
}
